package com.studyroom.controller;

import cn.hutool.core.net.Ipv4Util;
import com.studyroom.dto.QuestionDTO;
import com.studyroom.dto.Result;
import com.studyroom.entity.Answer;
import com.studyroom.entity.Question;
import com.studyroom.service.QuestionService;
import org.apache.tomcat.util.net.IPv6Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.net.util.IPAddressUtil;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/question")
public class QuestionController {
    @Autowired
    private QuestionService questionService;

    @RequestMapping("/getListByType")
    public Result getByType(@RequestParam String type){
        return questionService.getListByType(type);
    }
    @RequestMapping("/getById")
    public Result getById(@RequestParam Long id){
        return questionService.getById(id);
    }
    @GetMapping("/getAnswersByQuestionId")
    public Result getAnswersByQuestionId(@RequestParam Long id,@RequestParam Integer current){
        return questionService.getAnswersByQuestionId(id,current);
    }
    /*添加问题*/
    @RequestMapping("/add")
    public Result add(@RequestBody Question question){
        return questionService.add(question);
    }
    @RequestMapping("/del")
    public Result del(@RequestParam Long id){
        return questionService.del(id);
    }
    @RequestMapping("/getAnswers")
    public Result getAnswers(@RequestParam Long id){
        return questionService.getAnswers(id);
    }
    /*添加回复*/
    @RequestMapping("/addAnswer")
    public Result addAnswer(@RequestBody Answer answer) {
        return questionService.addAnswer (answer);
    }
    /*点赞*/
    @RequestMapping("/clickLike")
    public Result clickLike(@RequestParam Long id){
        return questionService.clickLike(id);
    }

    @RequestMapping("setSolve")
    public Result setSolve(@RequestBody Answer answer){
        return questionService.setSolve(answer);
    }
    @RequestMapping("/getListByTitleWithFuzzy")
    public Result getListByTitleWithFuzzy(@RequestParam String title){
        return questionService.getListByTitleWithFuzzy(title);
    }
    @RequestMapping("/pageview/add")
    public Result addPageView(HttpServletRequest request, @RequestParam Long questionId){
        return questionService.addPageView(questionId);
    }
}
